package com.charles.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolTest {
	public static void main(String[] args) {
		// ExecutorService threadPool = Executors.newFixedThreadPool(3);
		ExecutorService threadPool = Executors.newCachedThreadPool();
		//ExecutorService threadPool = Executors.newSingleThreadExecutor();
		for (int i = 0; i < 10; i++) {
			final int task = i;
			threadPool.execute(new Runnable() {

				@Override
				public void run() {
					try {
						Thread.sleep(20);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					for (int i = 0; i < 10; i++) {
						System.out.println(Thread.currentThread().getName() + ": " + i + " of task " + task);
					}
				}
			});
		}
		System.out.println("all task has committed!");
		threadPool.shutdown();
	}
}
